var t = require("../../../mycomponent/yz_pay/yz_pay"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        language: "",
        isclick: !0,
        order_id: "",
        store_id: "",
        orderData: null,
        balance: 0,
        payParams: "",
        info_form: {},
        order_sn: "",
        money: "",
        buttons: [],
        pay_sn: "订单编号",
        order_pay_id: "",
        uid: "",
        pid: "",
        status: ""
    },
    fromChild: function(t) {
        if ("0.00" == this.data.money) this.sureBtn(); else {
            var a = t.detail.submitArr;
            this.confirm(a);
        }
    },
    confirm: function(t) {
        var e = this, i = datas.value, n = a.getNetAddresss("plugin.room.frontend.code.pay-code");
        a._getNetWork({
            url: n,
            data: {
                id: this.data.id,
                money: this.data.code.money,
                pay_id: i,
                client_type: 1 == i ? 2 : ""
            },
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    if (3 == i) a.data[0] && wx.showToast({
                        title: "支付成功",
                        duration: 1e3,
                        icon: "none",
                        success: function(t) {
                            setTimeout(function() {
                                wx.redirectTo({
                                    url: "/packageH/liveAuthorization/liveAuthorization_scanCode/liveAuthorization_scanCode"
                                });
                            }, 1100);
                        }
                    }); else if (1 == i) {
                        var n = {
                            timeStamp: a.data.config.timestamp,
                            nonceStr: a.data.config.nonceStr,
                            package: a.data.config.package,
                            signType: a.data.config.signType,
                            paySign: a.data.config.paySign
                        };
                        console.log("payParams::::", n), e.WXPay(n);
                    }
                } else wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    WXPay: function(t) {
        wx.requestPayment({
            timeStamp: t.timeStamp,
            nonceStr: t.nonceStr,
            package: t.package,
            signType: t.signType ? t.signType : "MD5",
            paySign: t.paySign,
            success: function(t) {
                wx.redirectTo({
                    url: "/packageH/liveAuthorization/liveAuthorization_scanCode/liveAuthorization_scanCode"
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "支付失败请稍后重试",
                    icon: "none",
                    duration: 2e3,
                    success: function() {},
                    fail: function() {}
                });
            }
        });
    },
    onLoad: function(t) {
        var e = this;
        t.id && this.setData({
            id: t.id
        });
        var i = decodeURIComponent(t.scene);
        if (i) {
            var n = [];
            n = i.split(",");
            for (var o = 0; o < n.length; o++) {
                var s;
                "id" == (s = n[o].split("="))[0] && this.setData({
                    id: s[1]
                }), "mid" == s[0] && a._setMid(s[1]);
            }
        }
        var c = a.getNetAddresss("plugin.room.frontend.code.get-pay-type");
        a._getNetWork({
            url: c,
            data: {
                id: this.data.id
            },
            success: function(t) {
                var a = t.data.data;
                console.log("PayResult::::", a), 1 == t.data.result ? (e.hanleIcon(a), e.setData({
                    buttons: a.buttons,
                    code: a.code
                })) : (wx.showToast({
                    title: "授权码已被购买",
                    icon: "none",
                    duration: 2e3,
                    success: function(t) {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: "/packageH/liveAuthorization/liveAuthorization/liveAuthorization"
                            });
                        }, 1100);
                    }
                }), console.log("错误", t.data.msg));
            },
            fail: function(t) {}
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onUnload: function() {
        "activity" == this.data.tag && wx.navigateBack({
            delta: 1
        });
    }
});